<template>
  <a-layout :style="{height: '100%'}">
    <a-layout-sider v-model:collapsed="collapsed" :trigger="null" collapsible>
              <div class="logo">
              <img src="@/assets/Lizer-logo.svg" class="svg"/>
            </div>
      <a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline" @click="handelClick">
        <a-menu-item v-for="item in routerList" :key="item.path">
          <user-outlined />
          <span>{{ item.namespace }}</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="() => (collapsed = !collapsed)"
        />
        <menu-fold-outlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff' }"
      >
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script lang="ts">
import router from '@/router'
import { useStore } from 'vuex'
import {
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
  MenuUnfoldOutlined,
  MenuFoldOutlined
} from '@ant-design/icons-vue'
import axios from 'axios'
import { defineComponent, onMounted, reactive, ref } from 'vue'
export default defineComponent({
  components: {
    UserOutlined,
    // VideoCameraOutlined,
    // UploadOutlined,
    MenuUnfoldOutlined,
    MenuFoldOutlined
  },
  setup () {
    onMounted(() => {
      getRoute()
    })
    const store = useStore()
    const selectedKeys = ref<string[]>([store.state.adminMenukey])
    const routerList = reactive<any[]>([])
    const getRoute = () => {
      axios.get('/getRoute').then((res) => {
        routerList.splice(0, routerList.length, ...res.data.dataList)
      })
    }

    const handelClick = (item: { key: string }) => {
      router.push(item.key)
      store.commit('setAdminMenukey', item.key)
    }
    return {
      selectedKeys,
      handelClick,
      routerList,
      collapsed: ref<boolean>(false)
    }
  }
})
</script>
<style>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.3);
  margin: 16px;
}

.site-layout .site-layout-background {
  background: #fff;
}
</style>
